﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Windows.Browser;

namespace DeepTime.BootStrapper.Media
{
    /// <summary>
    /// Provides a MultiscaleTileSource for a single deepzoom image which draws its data from an aspx file.
    /// </summary>
    public class DynamicDeepZoomImageTileSource : MultiScaleTileSource
    {
        #region Class Memembers

        private string _ImageUri;

        #endregion Class Memembers

        #region Constructor

        /// <summary>
        /// Provides a MultiscaleTileSource for a single deepzoom image which draws its data from an aspx file.
        /// </summary>
        public DynamicDeepZoomImageTileSource(string imageUri, long imageWidth, long imageHeight, int tileWidth, int tileHeight, int tileOverlap)
            : base(imageWidth, imageHeight, tileWidth, tileHeight, tileOverlap)
        {
            _ImageUri = imageUri;
        }

        #endregion Constructor

        #region Override Methods

        protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY, IList<object> tileImageLayerSources)
        {
            string Url = string.Format("{0}?tilelevel={1}&tilepositionx={2}&tilepositiony={3}&imagename={4}", new object[]
            {
                new Uri(Application.Current.Host.Source, "../DeepZoomImage.aspx").OriginalString,
                HttpUtility.UrlEncode(tileLevel.ToString()),
                HttpUtility.UrlEncode(tilePositionX.ToString()),
                HttpUtility.UrlEncode(tilePositionY.ToString()),
                HttpUtility.UrlEncode(_ImageUri)
            });

            tileImageLayerSources.Add(new Uri(Url, UriKind.Absolute));
        }

        #endregion Override Methods
    }
}
